package com.zh.jbet.core.tournament.entity;

import com.zh.jbet.core.entity.BaseEntity;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "TMRESULT")
public class MatchResult implements BaseEntity, Serializable {

    private Long id;
    private Integer typeIdx;
    private TeamMatch game;
    private Integer homeGoalNo;
    private Integer awayGoalNo;

    @Id
    @SequenceGenerator(name = "S_TMRESULT", sequenceName = "S_TMRESULT", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_TMRESULT")
    @Override
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }

    @Basic
    public Integer getTypeIdx() {
        return typeIdx;
    }
    public void setTypeIdx(Integer typeIdx) {
        this.typeIdx = typeIdx;
    }

    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="GAMEID", nullable=false)
    public TeamMatch getGame() {
        return game;
    }
    public void setGame(TeamMatch game) {
        this.game = game;
    }
    @Basic
    public Integer getHomeGoalNo() {
        return homeGoalNo;
    }
    public void setHomeGoalNo(Integer homeGoalNo) {
        this.homeGoalNo = homeGoalNo;
    }
    @Basic
    public Integer getAwayGoalNo() {
        return awayGoalNo;
    }
    public void setAwayGoalNo(Integer awayGoalNo) {
        this.awayGoalNo = awayGoalNo;
    }

    @Transient
    public boolean isFilled() {
        return homeGoalNo != null && awayGoalNo != null;
    }
    @Transient
    public boolean isHomeWin() {
        return homeGoalNo > awayGoalNo;
    }
    @Transient
    public boolean isAwayWin() {
        return awayGoalNo > homeGoalNo;
    }

    @Override
    public String toString() {
        return isFilled() ? homeGoalNo + "-" + awayGoalNo : null;
    }
}
